From: Keir Fraser Date: Thu, 14 Jan 2010 09:41:34 +0000 (+0000) Subject: libxenlight: add fuse around generic_device_add related to invalid kinds X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~12743 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22?a=commitdiff_plain;h=b325401ccf9fe21f92e762257df94b2296c261a9;p=xen.git libxenlight: add fuse around generic_device_add related to invalid kinds prevent segfault in case the backend or frontend kinds have not been set to a correct kind value (or not initilized). Signed-off-by: Vincent Hanquez --- diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 7bbc924d18..726c543156 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -26,7 +26,7 @@ #include "libxl.h" #include "libxl_internal.h" -const char *string_of_kinds[] = { +static const char *string_of_kinds[] = { [DEVICE_VIF] = "vif", [DEVICE_VBD] = "vbd", [DEVICE_TAP] = "tap", @@ -45,6 +45,9 @@ int libxl_device_generic_add(struct libxl_ctx *ctx, libxl_device *device, struct xs_permissions backend_perms[2]; struct xs_permissions hotplug_perms[1]; + if (!is_valid_device_kind(device->backend_kind) || !is_valid_device_kind(device->kind)) + return ERROR_INVAL; + dom_path_backend = libxl_xs_get_dompath(ctx, device->backend_domid); dom_path = libxl_xs_get_dompath(ctx, device->domid); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 11698bc04e..34f2e3825f 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -68,7 +68,7 @@ typedef enum { DEVICE_CONSOLE, } libxl_device_kinds; -extern const char *string_of_kinds[]; +#define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE)) typedef struct { uint32_t backend_devid;